<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->integer('ticket')->default(0)->comment("可用抢单次数")->after('money');
        });

        Schema::create('users_ticket_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger("user_id")->comment("用户id");
            $table->integer('ticket')->default(0)->comment("抢购次数");
            $table->text("comment")->comment("备注");
            $table->unsignedTinyInteger('category')->default(0)->comment("操作类型: 1充值 2消费 3转入 4转出  5冲正");
            $table->timestamps();
            $table->index("user_id");
        });
        DB::statement("ALTER TABLE `users_ticket_log` COMMENT='用户抢购次数日志表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['ticket']);
        });

        Schema::dropIfExists('users_ticket_log');
    }
};
